1 Sort out the Data and Create the Timeresponse column

arm1 <- arm1 %>% 
  group_by(Day, Subject) %>% 
  arrange(Trial) %>% 
  mutate(Timebetween = (Time - lag(Time))*0.1) # Calculate the time between each presses (in seconds)



sortarm1 <- arrange(arm1, Subject, Day, Time) # Sort out the data 

head(sortarm1)

2 Creation of the Variable Mean of the time needed for pressing a lever for all trials

#head(arm1)

#sortarm1 %>% 
#  group_by(Day) %>% 
#  mutate(mean_timeb = mean(Timebetween, na.rm = TRUE)) %>% 
#  select(Subject, Day, mean_timeb)

TBD <- sortarm1 %>%
  group_by(Day, Subject) %>%
  summarise(mean_timeb = mean(Timebetween, na.rm=TRUE)) # New frame with the mean of timebetween for each day and each mouse. 

3 Analyse on Each Mouse

3.1 Mouse 1.1

M <- arm1[arm1$Subject=='1.1' ,]
summary(M)
##        X         Treatment    Subject           Task          Time      
##  Min.   :    1   S:  0     Min.   :1.1   0P005_WTL:479   Min.   :   53  
##  1st Qu.: 9068   T:979     1st Qu.:1.1   0P005_WTR:500   1st Qu.: 3167  
##  Median :17322             Median :1.1                   Median : 5231  
##  Mean   :17097             Mean   :1.1                   Mean   : 5209  
##  3rd Qu.:25330             3rd Qu.:1.1                   3rd Qu.: 7314  
##  Max.   :32703             Max.   :1.1                   Max.   :10813  
##                                                                         
##      Choice            Reward            Trial             Day        
##  Min.   :-1.0000   Min.   :-1.0000   Min.   :  1.00   Min.   : 1.000  
##  1st Qu.: 1.0000   1st Qu.:-1.0000   1st Qu.: 25.00   1st Qu.: 3.000  
##  Median : 1.0000   Median : 1.0000   Median : 49.00   Median : 6.000  
##  Mean   : 0.6507   Mean   : 0.3778   Mean   : 49.65   Mean   : 5.554  
##  3rd Qu.: 1.0000   3rd Qu.: 1.0000   3rd Qu.: 74.00   3rd Qu.: 8.000  
##  Max.   : 1.0000   Max.   : 1.0000   Max.   :100.00   Max.   :10.000  
##                    NA's   :5                                          
##       Ones     AllTrials      Timebetween     
##  Min.   :1   Min.   :  1.0   Min.   :  0.400  
##  1st Qu.:1   1st Qu.:245.5   1st Qu.:  7.300  
##  Median :1   Median :490.0   Median :  8.200  
##  Mean   :1   Mean   :490.0   Mean   :  9.018  
##  3rd Qu.:1   3rd Qu.:734.5   3rd Qu.:  9.300  
##  Max.   :1   Max.   :979.0   Max.   :105.000  
##                              NA's   :10
table(M$Choice)
## 
##  -1   1 
## 171 808
table(M$Reward)
## 
##  -1   1 
## 303 671
ML <- subset(arm1, Subject=='1.1' & Task=='0P005_WTL')
dim(ML)
## [1] 479  12
table(ML$Choice)
## 
##  -1   1 
##  44 435
MR <- subset(arm1, Subject=='1.1' & Task=='0P005_WTR')
dim(MR)
## [1] 500  12
table(MR$Choice)
## 
##  -1   1 
## 127 373
Nb_pres <- count(M, Choice, Day)
names(Nb_pres)[1] <- "Lever"
Nb_pres$Lever[Nb_pres$Lever==-1] <- "Low_lever"
Nb_pres$Lever[Nb_pres$Lever==1] <- "High_lever"
names(Nb_pres)[2] <- "day"
Nb_pres
quickplot(x=day, y=n, data = Nb_pres, color = Lever) +
  labs(y = "Number of presses",
       x = "Day",
       title = "Number of presses for each lever per day for mouse 1.1")# Graph number of presses on each

ggsave("Number of presses for each lever per day for mouse 1.1.png", width = 11, height = 8)


HL <- filter(Nb_pres,Lever=='High_lever')
barplot(HL$n, xlab='Day', ylab='Nb_presses', col ='darkred', main='Evolution of presses on the High_Lever for mouse 1.1',xlim=c(0,12), ylim=c(0,100)) 

LL <- filter(Nb_pres,Lever=='Low_lever')
barplot(LL$n, xlab='Day', ylab='Nb_presses', col ='darkblue', main='Evolution of presses on the Low_Lever for mouse 1.1',xlim=c(0,12), ylim=c(0,100) )

dM <- filter(sortarm1,Subject=='1.1')


qplot(Trial, Timebetween, data = dM, geom='line') +
  facet_wrap(~ Day) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Trial number",
       title = "Evolution of Timebetween (Trials) Data for mouse 1.1 for the 10 days of experiment")
## Warning: Removed 1 rows containing missing values (geom_path).

# Graphs showing the evolution of time between per trial for each day

ggplot(data = dM, aes(x = Trial, y = Timebetween)) +
  geom_boxplot() + 
  facet_grid(. ~ Day) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Trial number",
       title = "Evolution of Timebetween (Trials) Data for mouse 1.1 for the 10 days of experiment") +
  theme_linedraw() +
  theme(strip.text = element_text(size = rel(1)),
        panel.grid = element_blank())
## Warning: Continuous x aesthetic -- did you forget aes(group=...)?
## Warning: Removed 10 rows containing non-finite values (stat_boxplot).

M1 <- filter(TBD, Subject=='1.1')
ggplot(M1) + geom_point(aes(x = Day, y = mean_timeb))

gM1 <- ggplot(M1) + geom_line(aes(x = Day, y = mean_timeb)) + 
  labs(y = "Mean of Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween (mean) Data for mouse 1.1 for the 10 days of experiment")
gM1

Mouse 1.1 is a smart one. (Cf.Learning-Analysis) On TPGS treatment. The maximum number of trials is around 1000 (10 times 100 presses). He pressed 979 on 1000 trials. Among these 979 presses, 808 were the high rewarded lever and only 171 on the low lever. During the reversal phase (WTR), mouse 1.1 pressed 100 times the lever each 5 days. We can see that during the WTL session, he pressed 435/479 (90,8%) the high lever and 44/479 (9,2%) the low lever while during the reversal phase (WTR), he pressed 373/500 (74,6%) the high lever and 127/500 (25,4%) the low lever. The probability of success is obviously much better before the reversal.

Graphs :

The time of response decrease from day 2 to 5. (from 10,3s to 8s). We can see an increase of the time of response on day 6, which is the first day of reversal. Then the time of response decrease again to 8,25s.

4 Group of graph : Mice 1.1, 1.2, 2.3 and 2.4

#plot_grid(gM1,gM2,gM3,gM4, labels=c("M1.1", "M1.2","M2.3", "M2.4"), ncol = 2, nrow = 2) 

5 Analysing the timebetween per day and per mouse

ggplot(TBD) + geom_point(aes(x = Day, y = mean_timeb, color = Subject))
## Warning: Removed 2 rows containing missing values (geom_point).

qplot(Day, mean_timeb, data = TBD) +
  facet_wrap(~ Subject) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data per days for each mouse")
## Warning: Removed 2 rows containing missing values (geom_point).

6 Separation of the two groups

6.1 TPGS Analyse time of response

TBD2 <- sortarm1 %>% 
  group_by(Day, Subject) %>%
  mutate(mean_timeb = mean(Timebetween, na.rm = TRUE)) 
  

TPGS <- filter(TBD2, Treatment=='T')


TPGS2 <- TPGS %>% # New frame : mean of time of response for each day in the TPGS group
  group_by(Day) %>% 
  mutate(mean_day = mean(mean_timeb, na.rm = TRUE)) %>% 
  select(mean_day, Day) %>%
  distinct

TPGS2
ggplot(TPGS2) + geom_point(aes(x = Day, y = mean_day)) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the TPGS group - MEAN per DAY")

ggsave("EvolutionofTimeResponse_MEAN-per-DAY_TPGS.png", width = 11, height = 8)


ggplot(TPGS) + geom_point(aes(x = Day, y = mean_timeb)) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the TPGS group")
## Warning: Removed 1 rows containing missing values (geom_point).

ggsave("EvolutionofTimeResponse_TPGS-1.png", width = 11, height = 8)
## Warning: Removed 1 rows containing missing values (geom_point).
qplot(Day, mean_timeb, data = TPGS) +
  facet_wrap(~ Subject) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the TPGS group")
## Warning: Removed 1 rows containing missing values (geom_point).

qplot(Day, mean_timeb, data = TPGS, color=Subject, geom='path') +  
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the TPGS group")

ggsave("EvolutionofTimeResponseTPGS-2.png", width = 11, height = 8)

6.2 1-SORA-51 Analyse time of response

DRUG <- filter(TBD2, Treatment=='S')

DRUG2 <- DRUG %>% # New frame : mean of time of response for each day in the TPGS group
  group_by(Day) %>% 
  mutate(mean_day = mean(mean_timeb, na.rm = TRUE)) %>% 
  select(mean_day, Day) %>%
  distinct

DRUG2
summary(DRUG2$mean_day)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   11.47   12.31   14.00   13.85   14.69   16.97
ggplot(DRUG2) + geom_point(aes(x = Day, y = mean_day)) +
    labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the DRUG group  - MEAN for each DAY")

ggsave("EvolutionofTimeResponse-MEAN-per-DAY_SORA.png", width = 11, height = 8)


ggplot(DRUG) + geom_point(aes(x = Day, y = mean_timeb)) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the DRUG group")
## Warning: Removed 1 rows containing missing values (geom_point).

ggsave("EvolutionofTimeResponse-SORA-1.png", width = 11, height = 8)
## Warning: Removed 1 rows containing missing values (geom_point).
qplot(Day, mean_timeb, data = DRUG) +
  facet_wrap(~ Subject) +
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the DRUG group")
## Warning: Removed 1 rows containing missing values (geom_point).

qplot(Day, mean_timeb, data = DRUG, color=Subject, geom='path') +  
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the DRUG group")

ggsave("EvolutionofTimeResponseSORA-2.png", width = 11, height = 8)

7 Correction of the Data : Removing aberant subjects values.

7.1 In TPGS group

TPGScor <- subset(TPGS, Subject!='2.3' & Subject!='11.1')

qplot(Day, mean_timeb, data = TPGScor, color=Subject, geom='path') +  
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the TPGS_cor group")

TPGS[TPGS$mean_timeb>50 ,] # Identify aberrant subject ! 
summary(TPGScor$mean_timeb)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   5.666   8.959  10.155  10.917  11.925  26.629       1

7.2 In the Drug group

DRUG[DRUG$mean_timeb>100 ,] # Identify aberrant subject ! 
DRUGcor <- subset(DRUG, Subject!='7.4' & Subject!='9.1' & Subject!='10.4'& Subject!='10.3')

qplot(Day, mean_timeb, data = DRUGcor, color=Subject, geom='path') +  
  labs(y = "Time needed between two presses (in seconds)",
       x = "Day",
       title = "Evolution of Timebetween Data for the DRUGcor group")

summary(DRUGcor$mean_timeb)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   5.666   9.280  12.085  13.021  14.822  37.209       1

For the drug group, we can see that the mean time of response is approximately 13 seconds bewteen two presses while for the TPGS group the mean is approximately 10 seconds.

8 Other remarks :